﻿using PLCS.Domain.Equipments;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace PLCS.EquipmentService.BackgroundWorks.rgvs
{
    public class RGV1
    {
        private readonly ITaskRepository taskRepository;
        private readonly IEquipmentRepository equipmentRepository;
        private readonly IStationRepository stationRepository;

        public RGV1(ITaskRepository taskRepository,IEquipmentRepository equipmentRepository,IStationRepository stationRepository)
        {
            this.taskRepository = taskRepository;
            this.equipmentRepository = equipmentRepository;
            this.stationRepository = stationRepository;
        }

        public async Task Taskstart(TaskModel task)
        {
            var rgv1 = await equipmentRepository.FirstOrDefaultAsync(x=>x.EquName=="ST0034");
            if (rgv1.Status == DeviceStatus.空闲 && task.TaskStatus== Domain.Shared.Tasks.TaskStatus.未执行)
            {
                rgv1.Status = DeviceStatus.忙碌;
                task.TaskStatus = Domain.Shared.Tasks.TaskStatus.执行中;
                await taskRepository.UpdateAsync(task);
            }
        }

        public async Task EndTask()
        {
            var rgv1 = await equipmentRepository.FirstOrDefaultAsync(x => x.EquName == "ST0034");
            var ta = await taskRepository.FirstOrDefaultAsync(x=>x.TaskId== rgv1.CurrentTaskId);
            
        }
    }
}
